package com.bawei.caohao20240805.view.activity

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import androidx.lifecycle.Observer
import coil.load
import com.bawei.caohao20240805.MyApp
import com.bawei.caohao20240805.R
import com.bawei.caohao20240805.base.BaseActivity
import com.bawei.caohao20240805.databinding.ActivityShiBinding
import com.bawei.caohao20240805.viewmodel.ShiViewModel

class ShiActivity : BaseActivity<ShiViewModel,ActivityShiBinding>(R.layout.activity_shi) {
    override fun dataObSer() {
        mViewModel.rendata.observe(this, Observer {
            Toast.makeText(this, it.message, Toast.LENGTH_SHORT).show()
            if(it.status.equals("0000")){
                finish()
            }

        })
    }

    override fun initView() {
        mDing.img.setOnClickListener {
            startActivityForResult(Intent(Intent.ACTION_PICK).apply {
                                                                    type="image/*"
            },1000)
        }
        mDing.img2.setOnClickListener {
            startActivityForResult(Intent(Intent.ACTION_PICK).apply {
                type="image/*"
            },2000)
        }
        mDing.ren.setOnClickListener {
            mViewModel.getren(MyApp.userId,MyApp.sessionId,mDing.name.text.toString(),1,"ddfsdsf","sdfsdf","sdfsdf","sdffds","dsffsd")
        }

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if(requestCode==1000&&data!=null){
            mDing.img.load(data.data)
        }
        if(requestCode==2000&&data!=null){
            mDing.img2.load(data.data)
        }
    }
}